<?php
class Adm_Plugin_SessionCheck extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch (Zend_Controller_Request_Abstract $request)
    {
        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
        $options = $bootstrap->getOptions();
        $controller = $this->getRequest()->getControllerName();
        
        if (($controller != 'authentication') && ($controller != 'error')) {
            if ($options['auth']['active']) {
                $this->checkSession();
            }
        }
    }
    /**
     * checkSession
     */
    public function checkSession ()
    {
        $session = Zend_Registry::get('session');
        
        if (!isset( $session->userId )) {
            $this->getResponse()->setRedirect('/authentication/login')->sendResponse();
            exit;
        }
    }
}
